package org.spring.mybatis;

import com.yjp.mapper.OrderMapper;
import com.yjp.mapper.UserMapper;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.Map;

public class YjpImportBeanDefinitionRegister implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator){
//        ArrayList<Class> classes = new ArrayList<>();
//        classes.add(OrderMapper.class);
//        classes.add(UserMapper.class);
        Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(YjpMapperScan.class.getName());
        String path = (String) annotationAttributes.get("value");

        YjpScanner scanner = new YjpScanner(registry);
        scanner.scan(path);

//        for (Class aClass : classes) {
//            AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
//            beanDefinition.setBeanClass(YjpBeanFactory.class);
//            beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(aClass);
//            registry.registerBeanDefinition(aClass.getName(),beanDefinition);
//        }
    }
}
